﻿using System.Windows;
using ASoft.WPF.ViewModel;
using ASoft.WPF.View;
using System.Windows.Threading;
using ASoft.Service;


namespace ASoft.WPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            RC.Current.SerialPortService.WriteData(textBox1.Text);
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            var frm = new PLCView();
            frm.ShowDialog();
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            var bytes = RC.Current.SerialPortService.HexToByte(txtHex.Text);
            RC.Current.SerialPortService.WriteData(bytes);
        }

        private void ReceiveData_Click(object sender, RoutedEventArgs e)
        {
            byte[] receiveBytes = new byte[10];
            var ret = RC.Current.SerialPortService.SendCommand(null, ref receiveBytes, 1000);
            txtReceiveData.AppendText(ConvertUtility.ByteArrayToHexString(receiveBytes));

        }
    }
}
